package com.meitianhui.convenitenbuy.module.wallet.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.meitianhui.convenitenbuy.Constants;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.wallet.model.CouponBean;
import com.meitianhui.convenitenbuy.util.GlideUtils;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/3.
 * 拼团领
 */
public class WalletCouponAdapter extends BaseQuickAdapter<CouponBean.DiscountCard, BaseViewHolder> {
    private Context context;
    private Map<String, String> imgUrls;

    public WalletCouponAdapter(Context context, List<CouponBean.DiscountCard> data, Map<String, String> url) {
        super(R.layout.item_wallet_coupon, data);
        this.context = context;
        imgUrls = url;
    }

    @Override
    protected void convert(BaseViewHolder helper, CouponBean.DiscountCard bean) {
        if (bean != null) {
            boolean activated = TextUtils.equals(bean.getStatus(), Constants.SKU_STATUS_ACTIVATED);
            String category_id = bean.getCategory_id();
            if (TextUtils.equals(category_id, Constants.CONS_CASH)) {
                helper.setBackgroundRes(R.id.rl_wallet_coupon_item, R.mipmap.wallet_coupon_item_bg_money);
            } else if (TextUtils.equals(category_id, Constants.CONS_FREE)) {
                helper.setBackgroundRes(R.id.rl_wallet_coupon_item, R.mipmap.wallet_coupon_item_bg_gold);
            }
            helper.setVisible(R.id.iv_wallet_coupon_item_status, !activated);
            helper.setVisible(R.id.tv_wallet_coupon_tip, activated);
            helper.setText(R.id.tv_wallet_coupon_item_title, bean.getTitle());
            helper.setText(R.id.tv_wallet_coupon_item_content, bean.getStores_name());
            helper.setText(R.id.tv_wallet_coupon_item_time, context.getString(R.string.wallet_coupon_end_time) + (TextUtils.isEmpty(bean.getExpired_date())?"":bean.getExpired_date().substring(0, 10)));
            ImageView img = helper.getView(R.id.iv_wallet_coupon_item_img);
            GlideUtils.setCircleImage(context,imgUrls.get(bean.getLogo_pic_path()), R.mipmap.wallet_coupon_item_default, R.mipmap.wallet_coupon_item_default, img);
        }

    }


    public void replaceData(@NonNull Collection<? extends CouponBean.DiscountCard> data, Map<String, String> url) {
        replaceData(data);
        imgUrls = url;
    }

    public Map<String, String> getImgUrls(){
        return imgUrls;
    }
}
